﻿using System;
using System.Collections.Generic;
using System.IO;
using Character;
using UnityEngine;

/// <summary>通用材质 数据</summary>
public static class MaterialCustomData
{
	// Token: 0x06001350 RID: 4944 RVA: 0x0008AC84 File Offset: 0x00088E84
	private static void Setup()
	{
		for (int i = 0; i < MaterialCustomData.hairAcces.Length; i++)
		{
			MaterialCustomData.hairAcces[i] = new Dictionary<int, ColorParameter_PBR1>();
		}
		for (int j = 0; j < MaterialCustomData.wears.Length; j++)
		{
			MaterialCustomData.wears[j] = new Dictionary<int, ColorParameter_PBR2>();
		}
		for (int k = 0; k < MaterialCustomData.acces.Length; k++)
		{
			MaterialCustomData.acces[k] = new Dictionary<int, ColorParameter_PBR2>();
		}
	}

	// Token: 0x06001351 RID: 4945 RVA: 0x0008AD00 File Offset: 0x00088F00
	private static void Clear()
	{
		for (int i = 0; i < MaterialCustomData.hairAcces.Length; i++)
		{
			MaterialCustomData.hairAcces[i].Clear();
		}
		for (int j = 0; j < MaterialCustomData.wears.Length; j++)
		{
			MaterialCustomData.wears[j].Clear();
		}
		for (int k = 0; k < MaterialCustomData.acces.Length; k++)
		{
			MaterialCustomData.acces[k].Clear();
		}
	}

	// Token: 0x06001352 RID: 4946 RVA: 0x0008AD7C File Offset: 0x00088F7C
	public static void Save()
	{
		if (!Directory.Exists(MaterialCustomData.directory))
		{
			Directory.CreateDirectory(MaterialCustomData.directory);
		}
		FileStream fileStream = new FileStream(MaterialCustomData.file, FileMode.Create);
		BinaryWriter binaryWriter = new BinaryWriter(fileStream);
		binaryWriter.Write(10);
		binaryWriter.Write("hairAcces");
		for (int i = 0; i < MaterialCustomData.hairAcces.Length; i++)
		{
			binaryWriter.Write(MaterialCustomData.hairAcces[i].Count);
			foreach (KeyValuePair<int, ColorParameter_PBR1> keyValuePair in MaterialCustomData.hairAcces[i])
			{
				binaryWriter.Write(keyValuePair.Key);
				keyValuePair.Value.Save(binaryWriter);
			}
		}
		binaryWriter.Write("wears");
		for (int j = 0; j < MaterialCustomData.wears.Length; j++)
		{
			binaryWriter.Write(MaterialCustomData.wears[j].Count);
			foreach (KeyValuePair<int, ColorParameter_PBR2> keyValuePair2 in MaterialCustomData.wears[j])
			{
				binaryWriter.Write(keyValuePair2.Key);
				keyValuePair2.Value.Save(binaryWriter);
			}
		}
		binaryWriter.Write("acces");
		for (int k = 0; k < MaterialCustomData.acces.Length; k++)
		{
			binaryWriter.Write(MaterialCustomData.acces[k].Count);
			foreach (KeyValuePair<int, ColorParameter_PBR2> keyValuePair3 in MaterialCustomData.acces[k])
			{
				binaryWriter.Write(keyValuePair3.Key);
				keyValuePair3.Value.Save(binaryWriter);
			}
		}
		binaryWriter.Close();
		fileStream.Close();
	}

	// Token: 0x06001353 RID: 4947 RVA: 0x0008AF9C File Offset: 0x0008919C
	public static void Load()
	{
		MaterialCustomData.Setup();
		if (!File.Exists(MaterialCustomData.file))
		{
			return;
		}
		FileStream fileStream = new FileStream(MaterialCustomData.file, FileMode.Open);
		if (fileStream == null)
		{
			return;
		}
		BinaryReader binaryReader = new BinaryReader(fileStream);
		int num = binaryReader.ReadInt32();
		if (num < 0 || num > 10)
		{
			GlobalData.Debug_LogError("不明版本：" + num);
			binaryReader.Close();
			fileStream.Close();
			return;
		}
		if (binaryReader.ReadString() != "hairAcces")
		{
			GlobalData.Debug_LogError("无法读取自定义后的素材");
			return;
		}
		for (int i = 0; i < MaterialCustomData.hairAcces.Length; i++)
		{
			int num2 = binaryReader.ReadInt32();
			for (int j = 0; j < num2; j++)
			{
				int key = binaryReader.ReadInt32();
				ColorParameter_PBR1 colorParameter_PBR = new ColorParameter_PBR1();
				colorParameter_PBR.Load(binaryReader, (CUSTOM_DATA_VERSION)num);
				MaterialCustomData.SetHairAcce((HAIR_TYPE)i, key, colorParameter_PBR);
			}
		}
		if (binaryReader.ReadString() != "wears")
		{
			GlobalData.Debug_LogError("衣服之后的素材自定义无法读取");
			return;
		}
		for (int k = 0; k < MaterialCustomData.wears.Length; k++)
		{
			int num3 = binaryReader.ReadInt32();
			for (int l = 0; l < num3; l++)
			{
				int key2 = binaryReader.ReadInt32();
				ColorParameter_PBR2 colorParameter_PBR2 = new ColorParameter_PBR2();
				colorParameter_PBR2.Load(binaryReader, (CUSTOM_DATA_VERSION)num);
				MaterialCustomData.SetWear((WEAR_TYPE)k, key2, colorParameter_PBR2);
			}
		}
		if (binaryReader.ReadString() != "acces")
		{
			GlobalData.Debug_LogError("无法读取自acse以来的素材自定义");
			return;
		}
		for (int m = 0; m < MaterialCustomData.acces.Length; m++)
		{
			int num4 = binaryReader.ReadInt32();
			for (int n = 0; n < num4; n++)
			{
				int key3 = binaryReader.ReadInt32();
				ColorParameter_PBR2 colorParameter_PBR3 = new ColorParameter_PBR2();
				colorParameter_PBR3.Load(binaryReader, (CUSTOM_DATA_VERSION)num);
				MaterialCustomData.SetAcce((ACCESSORY_TYPE)m, key3, colorParameter_PBR3);
			}
		}
		binaryReader.Close();
		fileStream.Close();
	}

	// Token: 0x06001354 RID: 4948 RVA: 0x0008B194 File Offset: 0x00089394
	private static void SetHairAcce(HAIR_TYPE hairType, int key, ColorParameter_PBR1 color)
	{
		Dictionary<int, ColorParameter_PBR1> dictionary = MaterialCustomData.hairAcces[(int)hairType];
		if (!dictionary.ContainsKey(key))
		{
			dictionary.Add(key, color);
		}
		else
		{
			dictionary[key].Copy(color);
		}
	}

	// Token: 0x06001355 RID: 4949 RVA: 0x0008B1D0 File Offset: 0x000893D0
	public static void SetHairAcce(HAIR_TYPE hairType, HairPartParameter param)
	{
		MaterialCustomData.SetHairAcce(hairType, param.ID, param.acceColor);
	}

	// Token: 0x06001356 RID: 4950 RVA: 0x0008B1E4 File Offset: 0x000893E4
	private static void SetWear(WEAR_TYPE wearType, int key, ColorParameter_PBR2 color)
	{
		Dictionary<int, ColorParameter_PBR2> dictionary = MaterialCustomData.wears[(int)wearType];
		if (!dictionary.ContainsKey(key))
		{
			dictionary.Add(key, color);
		}
		else
		{
			dictionary[key].Copy(color);
		}
	}

	// Token: 0x06001357 RID: 4951 RVA: 0x0008B220 File Offset: 0x00089420
	public static void SetWear(WEAR_TYPE wearType, WearCustom param)
	{
		MaterialCustomData.SetWear(wearType, param.id, param.color);
	}

	// Token: 0x06001358 RID: 4952 RVA: 0x0008B234 File Offset: 0x00089434
	private static void SetAcce(ACCESSORY_TYPE acceType, int key, ColorParameter_PBR2 color)
	{
		Dictionary<int, ColorParameter_PBR2> dictionary = MaterialCustomData.acces[(int)acceType];
		if (!dictionary.ContainsKey(key))
		{
			dictionary.Add(key, color);
		}
		else
		{
			dictionary[key].Copy(color);
		}
	}

	// Token: 0x06001359 RID: 4953 RVA: 0x0008B270 File Offset: 0x00089470
	public static void SetAcce(AccessoryCustom custom)
	{
		MaterialCustomData.SetAcce(custom.type, custom.id, custom.color);
	}

	// Token: 0x0600135A RID: 4954 RVA: 0x0008B28C File Offset: 0x0008948C
	private static ColorParameter_PBR1 GetHairAcce(HAIR_TYPE hairType, int key)
	{
		Dictionary<int, ColorParameter_PBR1> dictionary = MaterialCustomData.hairAcces[(int)hairType];
		if (dictionary.ContainsKey(key))
		{
			return dictionary[key];
		}
		return null;
	}

	// Token: 0x0600135B RID: 4955 RVA: 0x0008B2B8 File Offset: 0x000894B8
	public static bool GetHairAcce(HAIR_TYPE hairType, HairPartParameter param)
	{
		ColorParameter_PBR1 hairAcce = MaterialCustomData.GetHairAcce(hairType, param.ID);
		if (hairAcce != null)
		{
			if (param.acceColor == null)
			{
				param.acceColor = new ColorParameter_PBR1();
			}
			param.acceColor.Copy(hairAcce);
			return true;
		}
		return false;
	}

	// Token: 0x0600135C RID: 4956 RVA: 0x0008B300 File Offset: 0x00089500
	private static ColorParameter_PBR2 GetWear(WEAR_TYPE wearType, int key)
	{
		Dictionary<int, ColorParameter_PBR2> dictionary = MaterialCustomData.wears[(int)wearType];
		if (dictionary.ContainsKey(key))
		{
			return dictionary[key];
		}
		return null;
	}

	// Token: 0x0600135D RID: 4957 RVA: 0x0008B32C File Offset: 0x0008952C
	public static bool GetWear(WEAR_TYPE wearType, WearCustom param)
	{
		ColorParameter_PBR2 wear = MaterialCustomData.GetWear(wearType, param.id);
		if (wear != null)
		{
			if (param.color == null)
			{
				param.color = new ColorParameter_PBR2();
			}
			param.color.Copy(wear);
			return true;
		}
		return false;
	}

	// Token: 0x0600135E RID: 4958 RVA: 0x0008B374 File Offset: 0x00089574
	private static ColorParameter_PBR2 GetAcce(ACCESSORY_TYPE acceType, int key)
	{
		Dictionary<int, ColorParameter_PBR2> dictionary = MaterialCustomData.acces[(int)acceType];
		if (dictionary.ContainsKey(key))
		{
			return dictionary[key];
		}
		return null;
	}

	// Token: 0x0600135F RID: 4959 RVA: 0x0008B3A0 File Offset: 0x000895A0
	public static bool GetAcce(AccessoryCustom custom)
	{
		ColorParameter_PBR2 acce = MaterialCustomData.GetAcce(custom.type, custom.id);
		if (acce != null)
		{
			if (custom.color == null)
			{
				custom.color = new ColorParameter_PBR2();
			}
			custom.color.Copy(acce);
			return true;
		}
		return false;
	}

	// Token: 0x04001876 RID: 6262
	public static readonly string directory = Application.dataPath + "/../UserData/Save";

	// Token: 0x04001877 RID: 6263
	public static readonly string file = Application.dataPath + "/../UserData/Save/MaterialsSaveData";

	// Token: 0x04001878 RID: 6264
	private static Dictionary<int, ColorParameter_PBR1>[] hairAcces = new Dictionary<int, ColorParameter_PBR1>[3];

	// Token: 0x04001879 RID: 6265
	private static Dictionary<int, ColorParameter_PBR2>[] wears = new Dictionary<int, ColorParameter_PBR2>[11];

	// Token: 0x0400187A RID: 6266
	private static Dictionary<int, ColorParameter_PBR2>[] acces = new Dictionary<int, ColorParameter_PBR2>[12];
}
